﻿<!DOCTYPE html>
<html>
<head>
	<script src="//code.jquery.com/jquery-3.7.1.js" type="text/javascript"></script>
	<script src="../../jsrender.js" type="text/javascript"></script>
	<link href="../resources/demos.css" rel="stylesheet" type="text/css" />

	<link href="../resources/movielist.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a href="../demos.html">JsRender Demos</a><br />

<h3>Helper functions</h3>

<pre>
{{>~format(name, "upper")}}

$.views.helpers({

    format: function( val, format ) {
        ...
        return val.toUpperCase();
        ...
    },

    ...
});
</pre>

<!--=================== Demo ===================-->

<!------------------ Templates ------------------>

<script id="movieTemplate" type="text/x-jsrender">
	<tr>
		<td>{{>~format(title, "upper")}}</td>
		<td>
			{{for languages}}
				{{>~format(name, "lower")}}
			{{/for}}
		</td>
	</tr>
</script>

<table>
	<thead><tr><th>Title</th><th>Languages</th></tr></thead>
	<tbody id="movieList"></tbody>
</table>

<!------------------ Script ------------------>

<script type="text/javascript">
	$.views.helpers({

		format: function( val, format ) {
			var ret;
			switch( format ) {
				case "upper":
					return val.toUpperCase();
				case "lower":
					return val.toLowerCase();
			}
		}
	});

	var movie = {
			title: "Eyes Wide Shut",
			languages: [
				{ name: "French" },
				{ name: "German" },
				{ name: "Spanish" }
			]
		};

	$( "#movieList" ).html(
		$( "#movieTemplate" ).render( movie )
	);

</script>

</body>
</html>
